package cc.eddic.pratice.programmingparadigms.emp03objlist.impl;

import cc.eddic.pratice.programmingparadigms.Result;
import cc.eddic.pratice.programmingparadigms.emp02list.ResultList;
import cc.eddic.pratice.programmingparadigms.emp03objlist.ObjectComparator;
import cc.eddic.pratice.programmingparadigms.emp03objlist.ObjectList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResultListCxmImpl extends ObjectList implements ResultList {

    private static final Logger log = LoggerFactory.getLogger(ObjectList.class);
    private Result[] results;
    private int size;
    public ResultListCxmImpl() {
        this(10);
    }

    public ResultListCxmImpl(int capacity) {
        if(capacity<0)
        {
            try {
                throw new Exception();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        results = (Result[])new Object[capacity];

    }

    @Override
    public void add(Result result) {
        if(size > results.length - 1)
        {
            Result[] newResults = (Result[])new Object[(size*3)/2+1];
            System.arraycopy(results, 0, newResults, 0, results.length);
            for(int i=0;i<results.length;i++)
            {
                newResults[i] = results[i];
            }
            results = newResults;
        }
        results[size++] = result;

    }

    @Override
    public Result get(int index) {
        if(index<0||index>=size)
        {
            try {
                throw new Exception();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return results[index];

    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public Result findByGender(String gender) {
        return null;
    }

    @Override
    public Result findByDepartment(String department) {
        return null;
    }

    @Override
    public Result findByJobTitle(String jobTitle) {
        return null;
    }

    @Override
    protected void sort(ObjectComparator comparator) {
        super.sort(comparator);
    }

    @Override
    public Result[] toArray() {
        return ResultList.super.toArray();
    }
}
